package www.truongnha.com;

import Config.setting;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.widget.Toast;

public class FragAct_Time extends FragmentActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragact_time);
	}

	/**
	 * Press back button twice to exit
	 */
	private long lastPressedTime;
	private Toast toast;

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			switch (event.getAction()) {
			case KeyEvent.ACTION_DOWN:
				if (event.getDownTime() - lastPressedTime < setting.PERIOD_TWICE_TO_EXIT) {
					toast.cancel();
					finish();
				} else {
					toast = Toast.makeText(getApplicationContext(), "",
							Toast.LENGTH_SHORT);
					toast.setText("Nhấn back một lần nữa để thoát | FragAct_Time");
					toast.show();
					lastPressedTime = event.getEventTime();
				}
				return true;
			}
		}
		return false;
	}

}